package sz.szsmk.citizencard.mvp.presenter;

import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.SearchViewRequest;
import sz.szsmk.citizencard.model.network.bean.response.SearchViewResponse;
import sz.szsmk.citizencard.mvp.contract.ISearchViewContact;
import sz.szsmk.citizencard.mvp.contract.ISettingContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;

import javax.inject.Inject;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/13 13:33
 * description:
 */
public class SearchViewPresenter extends IBasePresenter
        implements ISettingContact.ISettingPresenter<ISearchViewContact.ISearchViewView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public SearchViewPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void sendReq() {
        SearchViewRequest searchViewRequest = new SearchViewRequest();
        searchViewRequest.setAccess_token("60d98c885318bcfb1ff9d4c8598c91cc");
        searchViewRequest.setGroup_type(2);
        searchViewRequest.setKeyword("苏州");
        mNetworkDateSource.searchSpotAndHotelByKeyword(searchViewRequest, new SubscribeResult<SearchViewResponse>() {
            @Override
            protected void onOk(SearchViewResponse response) {
                if (response == null) {
                    return;
                }
                if (mView == null){
                    return;
                }
                ((ISearchViewContact.ISearchViewView) mView).getNewsInfoSucc(response);
            }

            @Override
            protected void onFailure(SearchViewResponse response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });

    }

}
